package com.hockeo.server.data;

import com.hockeo.shared.domain.persistent.Association;
import com.hockeo.shared.domain.persistent.Image;
import com.hockeo.shared.domain.persistent.Manager;
import com.hockeo.tinygds.TinyGDS;
import com.hockeo.tinygds.TinyGDSFactory;

/**
 * Data access object that encapsulates all interactions with the persistent datastore.
 *
 * @version $Id$
 * @author jjanke
 */
public final class DAO
{
  private static DAO           d_daoInstance;
  private final TinyGDSFactory d_tgdsFactory;

  /** Private constructor to avoid external instantiation. */
  private DAO()
  {
    d_tgdsFactory = new TinyGDSFactory();
    d_tgdsFactory.register( Manager.class, Association.class, Image.class );
  }

  /**
   * Returns a DAO instance ready to be used.
   */
  public static DAO get()
  {
    if ( d_daoInstance == null )
      d_daoInstance = new DAO();

    return d_daoInstance;
  }

  /**
   * Returns the currently active TinyGDSFactory.
   */
  public TinyGDSFactory getTGDSFactory()
  {
    return d_tgdsFactory;
  }

  /**
   * Returns a TinyGDS instance ready for use.
   */
  public TinyGDS begin()
  {
    return d_tgdsFactory.createTinyGDS();
  }
}
